﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LDSP.UI.Admin
{
    public partial class SystemConfig : LDSP.BRL.BaseAdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.RB())
                {
                    if (!IsPostBack)
                    {
                        this.InitDataSelect();
                    }
                }
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }

        protected bool RB()
        {
            return true;
        }

        protected void InitDataSelect()
        {
            this.txt_maxDownloadTimes.Text = BRL.SystemConfig.MaxDownloadTimes.ToString();
            this.txt_invalidAlert.Text = BRL.SystemConfig.InvalidAlertDays.ToString();
            this.txt_expireAlert.Text = BRL.SystemConfig.ExpireAlertDays.ToString();
            this.txt_addNewAlert.Text = BRL.SystemConfig.AddNewAlertDays.ToString();
        }


        protected void ValidateDataBefore()
        {
        }
        protected void ValidateDataAfter()
        {
            int tmp = this.GetInt(BRL.SystemConfig.MaxDownloadTimes);
            tmp = tmp < 1 ? 1 : tmp;
            BRL.SystemConfig.MaxDownloadTimes = tmp.ToString();
            tmp = this.GetInt(BRL.SystemConfig.InvalidAlertDays);
            tmp = tmp < 1 ? 1 : tmp;
            BRL.SystemConfig.InvalidAlertDays = tmp.ToString();
            tmp = this.GetInt(BRL.SystemConfig.ExpireAlertDays);
            tmp = tmp < 1 ? 1 : tmp;
            BRL.SystemConfig.ExpireAlertDays = tmp.ToString();
            tmp = this.GetInt(BRL.SystemConfig.AddNewAlertDays);
            tmp = tmp < 1 ? 1 : tmp;
            BRL.SystemConfig.AddNewAlertDays = tmp.ToString();
        }
        protected void SetData()
        {
            this.ValidateDataBefore();
            BRL.SystemConfig.MaxDownloadTimes = this.txt_maxDownloadTimes.Text.Trim();
            BRL.SystemConfig.InvalidAlertDays = this.txt_invalidAlert.Text.Trim();
            BRL.SystemConfig.ExpireAlertDays = this.txt_expireAlert.Text.Trim();
            BRL.SystemConfig.AddNewAlertDays = this.txt_addNewAlert.Text.Trim();
            this.ValidateDataAfter();
        }

        protected void btn_ok_Click(object sender, EventArgs e)
        {
            try
            {
                this.SetData();
                this.JSAlert("更新成功！");
                this.InitDataSelect();
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }
    }

}